package com.example.vueblog.common.enums;

import lombok.Getter;

/**
 * 常量枚举类
 * @author yushunshun
 * @date 2022/5/28 17:39
 */
@Getter
public enum ResultEnum {

    SUCCESS(1001, "成功"),

    FAILURE(1002, "失败"),

    USER_NEED_AUTHORITIES(2001, "用户未登录"),

    USER_LOGIN_FAILED(2002, "用户账号或密码错误"),

//    USER_LOGIN_SUCCESS(2003, "用户登录成功"),

    USER_NO_ACCESS(2004, "用户无权访问"),

//    USER_LOGOUT_SUCCESS(2005, "用户登出成功"),

    TOKEN_IS_BLACKLIST(2006, "此token为黑名单"),

    LOGIN_IS_OVERDUE(2007, "登录已失效"),

    USER_LOGIN_CODE_FAILURE(2008, "验证码已失效"),

    USER_LOGIN_CODE_ERROR(2009, "验证码错误"),

    VAILD_EXCEPTION(3001,"参数格式校验失败")
    ;

    private Integer code;

    private String message;

    ResultEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * @deprecation:通过code返回枚举
     */
    public static ResultEnum parse(int code) {
        ResultEnum[] values = values();
        for (ResultEnum value : values) {
            if (value.getCode() == code) {
                return value;
            }
        }
        throw new RuntimeException("Unknown code of ResultEnum");
    }
}
